// Realistic Unit Modification Assets Dialog 
// v. Beta

// IDD and IDC ------------------------

RUM_SUP_IDD = 1060;
RUM_BttnExit_IDC = 1061;
RUM_BttnSUP_IDC = 1062;
RUM_ListSUP_IDC = 1063;
RUM_ListSUPpayload_IDC = 1064;
RUM_BttnSUPType_IDC = 1065;

// Code -------------------------------

// Buttons ----------------------------

RUM_BttnSUP = {
	_payload = RUM_SUP_Payload select (lbCurSel RUM_ListSUPpayload_IDC);
	_id = lbCurSel RUM_BttnSUPType_IDC;
	_type = lbText [RUM_BttnSUPType_IDC,_id];
	if(RUM_SUP_NonSpawn) then {
		_arry = RUM_SUPAircraft select (lbCurSel RUM_ListSUP_IDC);
		_sel = lbCurSel RUM_ListSUP_IDC;
		[_arry,_payload,_type] execVM (RUM_PATH+"Supply\callDrop.sqf");
		// this will delete the vehicle from the RUM PDA when selected for use.
		RUM_SUPAircraft set [_sel,"del"];
		RUM_SUPAircraft = RUM_SUPAircraft - ["del"];
		
	} else {
		_arry = RUM_SUPAircraft_Spawn select (lbCurSel RUM_ListSUP_IDC);
		[_arry,_payload,_type] execVM (RUM_PATH+"Supply\callDrop_spwn.sqf");
		_sel = lbCurSel RUM_ListSUP_IDC;
		// this will delete the vehicle from the RUM PDA when selected for use.
		RUM_SUPAircraft_Spawn set [_sel,"del"];
		RUM_SUPAircraft_Spawn = RUM_SUPAircraft_Spawn - ["del"];
	};
	if(true)exitwith{closeDialog 0};
};

// Lists ------------------------------

RUM_FillListSUP = {
	lbClear RUM_ListSUP_IDC;
	_list1 = [];
	_airlist = [];
	if(RUM_SUP_NonSpawn)then{_airlist = RUM_SUPAircraft}else{_airlist = RUM_SUPAircraft_Spawn};
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n+1}] do {
		_air = _airlist select (_n-1);
		_text = _air select 1;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListSUP_IDC,_x]} foreach _list1;
	lbSetCurSel [RUM_ListSUP_IDC,0];
	if(true)exitWith{};
};

RUM_FillListSUPpayload = {
	lbClear RUM_ListSUPpayload_IDC;
	_list1 = [];
	_airlist = RUM_SUP_Payload;
	for [{_n = 1},{_n <= (count _airlist)},{_n = _n+1}] do {
		_air = _airlist select (_n-1);
		_text = _air select 0;
		_list1 = _list1 + [_text];
   	};
	{lbAdd [RUM_ListSUPpayload_IDC,_x]} foreach _list1;
	lbSetCurSel [RUM_ListSUPpayload_IDC,0];
	if(true)exitWith{};
};

RUM_SUPType = {
	private ["_tst","_tst2","_types","_heloarr"];
	_tst = -1;
	_tst2 = -1;
	while {dialog} do {
		_sel = lbCurSel RUM_ListSUP_IDC;
		_sel2 = lbCurSel RUM_ListSUPpayload_IDC;
		if(!(_sel == _tst) or !(_sel2 == _tst2))then{
			lbClear RUM_BttnSUPType_IDC;
			if(RUM_SUP_NonSpawn)then{_heloarr = RUM_SUPAircraft select _sel}else{_heloarr = RUM_SUPAircraft_Spawn select _sel};
			_payarr = RUM_SUP_Payload select _sel2;
			_types = [];
			if(RUM_SUP_slingLoad and !("plane" in _heloarr)) then {_types = _types + ["Sling Load"]};
			if((_payarr select 3 <= RUM_SUP_payloadParaLimit) or ("plane" in _heloarr)) then {_types = _types + ["Para Drop"]};
			{lbAdd [RUM_BttnSUPType_IDC,_x]} foreach _types;
			lbSetCurSel [RUM_BttnSUPType_IDC,0];
		};
		_tst = _sel;
		_tst2 = _sel2;
	};
	if(true)exitWith{};
};

// Init -------------------------------
createDialog "RUM_SUP";
call RUM_FillListSUP;
call RUM_FillListSUPpayload;
call RUM_SUPType;

if(true)exitwith{};